from demo import test
from table import *
from row import *

@test
def slurped():
  t=Table().slurp('data/test1.csv')
  return (
    "[{1: ['1', '2', 3.0, '4']}, {2: ['5', '6', 7.0, '8']}]",
    str(t.data))

@test
def closested():
  Row.id=0
  t=Table().slurp('data/test2.csv')
  return ("{2: [1.0, '3', 3.0, '4']}", 
          str(t.closest(t.data[0])))

@test
def furthested():
  Row.id=0
  t=Table().slurp('data/test2.csv')
  return ("{3: [5.0, '6', 7.0, '8']}",
          str(t.furthest(t.data[0])))

@test
def cloned():
  Row.id=0
  t0=Table().slurp('data/test2.csv')
  h1 = t0.header
  t1=t0.clone( [[1.0,'2',3.0,'4']
               ,[1.0,'3',3.0,'4']
               ,[5.0,'6',7.0,'8']
               ,[6.0,'6',6.0,'8']
               ] )
  h2 = t1.header
  return True,str(h1)==str(h2)
